﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StackOnArray
{
    class Program
    {
        static void Main(string[] args)
        {
            UserStack<String> myStack = new UserStack<String>(10);

            for (Int32 i = 0; i < myStack.Length; i++)
            {
                myStack.PushToStack(i.ToString());
            }

            for (Int32 i = 0; i < myStack.Length; i++)
            {
                Console.Write(" {0}",myStack.PopToStack());
            }

            Console.WriteLine();
            Console.ReadLine();
        }
    }

    public class UserStack<T>
    {
        private Int32 _nomer = 0;
        private T[] masStack;

        public UserStack(Int32 razmer)
        {
            masStack = new T[razmer];
        }

        public Int32 Length
        {
            get { return masStack.Length; }
        }

        public void PushToStack(T elem)
        {
            masStack[_nomer] = elem;
            _nomer++;
        }

        public T PopToStack()
        {
            _nomer--;
            return masStack[_nomer];
        }
    }
}
